﻿using Microsoft.Xna.Framework.Input;

namespace GameLibrary.Input
{
    public enum MouseButtons
    {
        LeftButton,
        MiddleButton,
        RightButton,
        ExtraButton1,
        ExtraButton2
    }


    public class CMouseButton
    {
        MouseButtons KeyCode;
        bool Last;
        bool Current;

        public bool Pressed;
        public bool Released;
        public bool Hold;
        public bool Untouched;

        public CMouseButton(MouseButtons key)
        {
            KeyCode = key;
            Current = Last = Pressed
            = Released = false;
        }

        public void Update()
        {


            Last = Current;
            Current = IsDown(KeyCode);
            Pressed = (Current && !Last);
            Released = (!Current && Last);
            Hold = (Current && Last);
            Untouched = (!Current && !Last);
        }

        bool IsDown(MouseButtons button)
        {
            MouseState mouseState = Mouse.GetState();
            switch (button)
            {
                case MouseButtons.LeftButton:
                    return mouseState.LeftButton == ButtonState.Pressed;
                case MouseButtons.MiddleButton:
                    return mouseState.MiddleButton == ButtonState.Pressed;
                case MouseButtons.RightButton:
                    return mouseState.RightButton == ButtonState.Pressed;
                case MouseButtons.ExtraButton1:
                    return mouseState.XButton1 == ButtonState.Pressed;
                case MouseButtons.ExtraButton2:
                    return mouseState.XButton2 == ButtonState.Pressed;
                default:
                    return false;
            }
        }
    }
}
